﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master/b.master" %>

<script runat="server">

</script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" Runat="Server">
    <script src="assets/js/plugins/url/url.js?version=2.5.0"></script>

    <script type="text/javascript">
        $(function () {
            //如果有token和userid
            if ($.url("?token") != undefined && $.url("?userid") != undefined &&
                $.url("?token").length > 0 && $.url("?userid").length > 0 &&
                $.url("?username") != undefined && $.url("?username").length > 0 &&
                $.url("?LoginStatus") != undefined && $.url("?LoginStatus").length > 0) {
                console.log('已检测登录,获取登录后信息');
                console.log($.url("?token"));
                console.log($.url("?userid"));
                console.log($.url("?LoginStatus"));
                if ($.url("?LoginStatus") == "AlreadyLogin") {
                    var result_ok = confirm("检测到本地已经登录了单点登录平台,是否一键登录?");
                    if (result_ok) {
                        //使用已经存在的信息进行登录
                        Y.API2("Login",
                            "LoginByToken",
                            {
                                "UserName": $.url("?username"),
                                "UserId": $.url("?userid"),
                                "Token": $.url("?token")
                            }, function (data) {
                                if (data.Success == false) {
                                    layer.alert(data.Message);
                                } else {
                                    sessionStorage.setItem('login-info', JSON.stringify(data));
                                    //加载返回的sso信息
                                    var onlineInfo = data.OnlineInfo;
                                    if (!Y.checkNull(onlineInfo) && !Y.checkNull(onlineInfo.Token) &&
                                        !Y.checkNull(onlineInfo.UserID) && !Y.checkNull(onlineInfo.UserName)) {
                                        //登录成功后,转入主页
                                        location.href = "index.aspx";
                                    }
                                }
                            });
                    } else {
                        //转入正常登录流程
                        location.href = "Login.aspx?CheckOnline=true";
                    }
                } else if ($.url("?LoginStatus") == "LoginInOtherPlace") {
                    var result_ok = confirm("检测到用户已在其他电脑登录,是否强制登录?");
                    if (result_ok) {
                        //强制登录
                        top.location.href = "Login.aspx?CheckOnline=true&ForceLogin=1";
                    } else {
                        //转入正常登录流程
                        top.location.href = "Login.aspx?CheckOnline=true";
                    }
                } else if ($.url("?LoginStatus") == "success") {
                    //登录成功后,转入主页
                    top.location.href = "index.aspx";
                }
            } else {
            }


        });
    </script>

</asp:Content>
